﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Aker.DevTeam;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using Extensions;

namespace Aker
{
    public partial class Users : XForm
    {
        public Users()
        {
            InitializeComponent();
        }

        private void gv_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            gv.EndEditing();
            Data.TAM.KullaniciTableAdapter.Update(gv.GetDataRow(e.RowHandle));
        }

        public RepositoryItemGridLookUpEdit GetYetkiGLE()
        {
            DataTable dataSource = new DataTable();

            dataSource.Columns.Add("YetkiId", typeof(int));
            dataSource.Columns.Add("Yetki", typeof(string));

            dataSource.Rows.Add(new object[] { 1, "Depo" });
            dataSource.Rows.Add(new object[] { 2, "Depo Yönetim" });
            dataSource.Rows.Add(new object[] { 3, "Pazarlama" });
            dataSource.Rows.Add(new object[] { 4, "Pazarlama Yönetim" });
            dataSource.Rows.Add(new object[] { 5, "Yönetim" });            

            return Utility.GetGLESablon(dataSource, "Yetki", "YetkiId");
        }

        private void Users_Load(object sender, EventArgs e)
        {
            Data.TAM.KullaniciTableAdapter.Fill(Data.DB.Kullanici);
            Data.DB.Kullanici.TableNewRow += Kullanici_TableNewRow;
            gv.Init(Data.DB.Kullanici);            
            gv.MakeEditable("KullaniciId");
            gv.Columns["YetkiId"].ColumnEdit = GetYetkiGLE();

            gv.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
            gv.OptionsView.ShowViewCaption = false;
          

            if (AppSession.Language == "TR")            
                gv.SetCaptions("KullaniciId:#","KullaniciAdi:Kullanıcı Adı","ePosta:e-posta","YetkiId:Departman");
            else
                gv.SetCaptions("KullaniciId:#","KullaniciAdi:User Name","Parola:Password","AdSoyad:Name Surname","ePosta:e-mail","YetkiId:Department");

            this.Text = Language.Users.Header;
            gv.BestFitColumns();
        }

        void Kullanici_TableNewRow(object sender, DataTableNewRowEventArgs e)
        {
            e.Row["Yonetici"] = false;
        }
    }
}
